home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 419_01 / odmg10 / util / scripts / mergelib.cpp < prev    next >
Encoding:
Text File  |  1994-02-13  |  2.6 KB  |  100 lines

  1. /**/#!/bin/sh
  2. /**/#
  3. /**/# $XConsortium: mergelib.cpp,v 1.2 89/10/17 12:09:30 jim Exp $
  4. /**/# 
  5. /**/# Copyright 1989 Massachusetts Institute of Technology
  6. /**/# 
  7. /**/# Permission to use, copy, modify, distribute, and sell this software and its
  8. /**/# documentation for any purpose is hereby granted without fee, provided that
  9. /**/# the above copyright notice appear in all copies and that both that
  10. /**/# copyright notice and this permission notice appear in supporting
  11. /**/# documentation, and that the name of M.I.T. not be used in advertising or
  12. /**/# publicity pertaining to distribution of the software without specific,
  13. /**/# written prior permission.  M.I.T. makes no representations about the
  14. /**/# suitability of this software for any purpose.  It is provided "as is"
  15. /**/# without express or implied warranty.
  16. /**/# 
  17. /**/# M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  18. /**/# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  19. /**/# BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  20. /**/# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  21. /**/# OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  22. /**/# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  23. /**/# 
  24. /**/# Author:  Jim Fulton, MIT X Consortium
  25. /**/# 
  26. /**/# mergelib - merge one library into another; this is commonly used by X
  27. /**/#     to add the extension library into the base Xlib.
  28. /**/#
  29.  
  30. usage="usage:  $0  to-library from-library [object-filename-prefix]"
  31. objprefix=_
  32.  
  33. case $# in
  34.     2) ;;
  35.     3) objprefix=$3 ;;
  36.     *) echo "$usage" 1>&2; exit 1 ;;
  37. esac
  38.  
  39. tolib=$1
  40. fromlib=$2
  41.  
  42. if [ ! -f $fromlib ]; then
  43.     echo "$0:  no such from-library $fromlib" 1>&2
  44.     exit 1
  45. fi
  46.  
  47. if [ ! -f $tolib ]; then
  48.     echo "$0:  no such to-library $tolib" 1>&2
  49.     exit 1
  50. fi
  51.  
  52.  
  53. /**/#
  54. /**/# Create a temp directory, and figure out how to reference the 
  55. /**/# object files from it (i.e. relative vs. absolute path names).
  56. /**/#
  57.  
  58. tmpdir=tmp.$$
  59. origdir=..
  60.  
  61. mkdir $tmpdir
  62.  
  63. if [ ! -d $tmpdir ]; then
  64.     echo "$0:  unable to create temporary directory $tmpdir" 1>&2
  65.     exit 1
  66. fi
  67.  
  68. case "$fromlib" in
  69.     /?*) upfrom= ;;
  70.     *)  upfrom=../ ;;
  71. esac
  72.  
  73. case "$tolib" in
  74.     /?*) upto= ;;
  75.     *)  upto=../ ;;
  76. esac
  77.  
  78.  
  79. /**/#
  80. /**/# In the temp directory, extract all of the object files and prefix
  81. /**/# them with some symbol to avoid name clashes with the base library.
  82. /**/#
  83. cd $tmpdir
  84. ar x ${upfrom}$fromlib
  85. for i in *.o; do
  86.     mv $i ${objprefix}$i
  87. done
  88.  
  89.  
  90. /**/#
  91. /**/# Merge in the object modules, ranlib (if appropriate) and cleanup
  92. /**/#
  93. ARCMD ${upto}$tolib *.o
  94. /**/# RANLIB ${upto}$tolib
  95. cd $origdir
  96. rm -rf $tmpdir
  97.  
  98.  
  99.  
  100.